package com.ruoyi.dm.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.dm.domain.po.SpaceTargetMeasurePO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface SpaceTargetMeasureMapper extends BaseMapper<SpaceTargetMeasurePO> {

    /**
     * 删除重复名字的数据
     * @return
     */
    @Delete("delete from COLLECT_MEASURE_INFO where id  in " +
            "(  SELECT aid FROM (" +
            "SELECT aid,bid FROM (" +
            "SELECT id AS aid FROM COLLECT_MEASURE_INFO WHERE CODE  IN ( select CODE from ( select count(1) as num,CODE from COLLECT_MEASURE_INFO group by CODE) where num >=2 ) ) a LEFT  JOIN " +
            "( select id AS bid from ( select count(1) as num,max(id) AS id from COLLECT_MEASURE_INFO group by CODE) where num >=2 ) b ON aid = bid ) WHERE bid IS NULL)")
    int deleteRepeate();
}
